// -----------------------------------------------------------------------
//  <copyright file="GetResourcePageQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/5 22:15</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.Entities;

namespace DaprPlus.Authorization.Application.Queries;

[AuthConfig(typeof(Resource), ResourceAccessType.RoleLimit, "GetPage")]
public class GetResourcePageQuery : PageQuery<PageResult<ResourceOutDto>>
{ }

public class GetResourcePageQueryHandler(IQueryRepository<Resource> queryRepository)
    : IRequestHandler<GetResourcePageQuery, PageResult<ResourceOutDto>>
{
    public async Task<PageResult<ResourceOutDto>> Handle(GetResourcePageQuery request, CancellationToken cancellationToken)
    {
        var spec = new PageQuerySpecification<Resource>(request.PageCondition, request.FilterGroup);
        var page = await queryRepository.GetPageAsync<ResourceOutDto>(spec, cancellationToken);
        return page;
    }
}

